using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BLL;


using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Runtime.InteropServices;


namespace QLNhanKhau
{
    public partial class frmMenu : DevComponents.DotNetBar.Metro.MetroForm
    {
        public frmMenu()
        {
            InitializeComponent();
            
        }

        private void addNewTab(string strTabName, System.Windows.Forms.UserControl ucContent)
        {
            //-----------If exist tabpage then exit---------------
            foreach (DevComponents.DotNetBar.TabItem tabPage in tabMain.Tabs)
                if (tabPage.Text == strTabName)
                {
                    tabMain.SelectedTab = tabPage;
                    return;
                }
            //-------------------------Clear Tab Before---------------
            if (tabMain.Tabs.Count > 1)
             tabMain.Tabs.RemoveAt(1);

            TabControlPanel newTabPanel = new DevComponents.DotNetBar.TabControlPanel();
            DevComponents.DotNetBar.TabItem newTabPage = new DevComponents.DotNetBar.TabItem(this.components);
            newTabPage.ImageIndex = 0;
            //newTabPage.MouseDown += new System.Windows.Forms.MouseEventHandler(tabItem_MouseDown);
            newTabPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            newTabPanel.Location = new System.Drawing.Point(0, 26);
            newTabPanel.Name = "panel" + strTabName;
            newTabPanel.Padding = new System.Windows.Forms.Padding(1);
            newTabPanel.Size = new System.Drawing.Size(1230, 384);
            newTabPanel.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(142)))), ((int)(((byte)(179)))), ((int)(((byte)(231)))));
            newTabPanel.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(237)))), ((int)(((byte)(254)))));
            newTabPanel.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
            newTabPanel.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(97)))), ((int)(((byte)(156)))));
            newTabPanel.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right)
                        | DevComponents.DotNetBar.eBorderSide.Bottom)));
            newTabPanel.Style.GradientAngle = 90;
            newTabPanel.TabIndex = 2;
            newTabPanel.TabItem = newTabPage;
            //-------------New  tab page---------------------
            Random ran = new Random();
            newTabPage.Name = strTabName + ran.Next(100000) + ran.Next(22342);
            newTabPage.AttachedControl = newTabPanel;
            newTabPage.Text = strTabName;
            ucContent.Dock = DockStyle.Fill;
            newTabPanel.Controls.Add(ucContent);
            //------------add Tab page to Tab control-------------
            tabMain.Controls.Add(newTabPanel);
            tabMain.Tabs.Add(newTabPage);
            tabMain.SelectedTab = newTabPage;
        }

        

        private void tabMain_TabItemClose(object sender, TabStripActionEventArgs e)
        {
            tabMain.Tabs.Remove(tabMain.SelectedTab);
        }
        

        private void btnKhaiSinh_Click(object sender, EventArgs e)
        {
            UCKhaiSinh ucks = new UCKhaiSinh();
            addNewTab("Khai sinh", ucks);
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {

        }

        private void btnKhaiTu_Click(object sender, EventArgs e)
        {
            UCKhaiTu uckt = new UCKhaiTu();
            addNewTab("Khai tử", uckt);
        }

        private void btnSHK_Click(object sender, EventArgs e)
        {
            UCSHK ucshk = new UCSHK();
            addNewTab("Cấp SHK", ucshk);
        }

        private void btnTachSo_Click(object sender, EventArgs e)
        {
            UCTachKhau uctk = new UCTachKhau();
            addNewTab("Tách sổ", uctk);
        }

        private void btnChuyenDi_Click(object sender, EventArgs e)
        {
            UCChuyenDin uccdn = new UCChuyenDin();
            addNewTab("Chuyển đi", uccdn);
        }

        private void btnChuyenHo_Click(object sender, EventArgs e)
        {
            UCChuyenDi uccdi = new UCChuyenDi();
            addNewTab("Chuyển hộ", uccdi);
        }

        private void btnChuyenDen_Click(object sender, EventArgs e)
        {
            UCChuyenDen uccd = new UCChuyenDen();
            addNewTab("Chuyển đến", uccd);
        }

        private void btnBaoCao_Click(object sender, EventArgs e)
        {
            UCBaoCao ucbc = new UCBaoCao();
            addNewTab("Báo cáo", ucbc);
        }

        private void btnQuanTri_Click(object sender, EventArgs e)
        {
            UCQuanTri ucnd = new UCQuanTri();
            addNewTab("Quản trị", ucnd);
        }

        private void btnTuoi_Click(object sender, EventArgs e)
        {
            UCDoTuoi ucdt = new UCDoTuoi();
            addNewTab("Thống kê tuổi", ucdt);
        }

        private void frmMenu_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Windows.Forms.Application.Exit();
        }

        

        private void btnTimKiem_Click_1(object sender, EventArgs e)
        {
            UCTimKiem uctk = new UCTimKiem();
            addNewTab("Tìm kiếm", uctk);
        }

        private void frmMenu_Load(object sender, EventArgs e)
        {
            //labGioiThieu.Text = "HỆ THỐNG QUẢN LÝ NHÂN KHẨU PHƯỜNG/XÃ "+ThietLapBLL.LoadDiaPhuong();
            labGioiThieu.Text = labGioiThieu.Text + ThietLapBLL.LoadDiaPhuong();
            if (frmDangNhap.user_login.MaCV == 3)
            {
                ribbonTabItem3.Visible = false;
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            DialogResult result= System.Windows.Forms.MessageBox.Show("Thoát khỏi hệ thống", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            switch (result)
            { 
                case DialogResult.OK:
                    System.Windows.Forms.Application.Exit();
                    break;
                case DialogResult.Cancel:
                    break;
            }
        }

        private void btnUpdateSHK_Click(object sender, EventArgs e)
        {
            UCUpdateSHK ucupdateSHK = new UCUpdateSHK();
            addNewTab("Cập nhật Sổ hộ khẩu", ucupdateSHK);

        }

        private void btnUpdateKhaiSinh_Click(object sender, EventArgs e)
        {
            UCUpdateKhaiSinh ucupdateKS = new UCUpdateKhaiSinh();
            addNewTab("Cập nhật Khai sinh", ucupdateKS);
        }

        private void btnUpdateKhaiTu_Click(object sender, EventArgs e)
        {
            UCUpdateKhaiTu ucupdateKT = new UCUpdateKhaiTu();
            addNewTab("Cập nhật khai tử", ucupdateKT);
        }

        private void btnUpdateChuyenKhau_Click(object sender, EventArgs e)
        {
            UCUpdateChuyenDen ucupdateCDen = new UCUpdateChuyenDen();
            addNewTab("Cập nhật Chuyển đến", ucupdateCDen);
        }

        private void btnUpdateChuyenDi_Click(object sender, EventArgs e)
        {
            UCUpdateChuyenDi ucupdateCDi = new UCUpdateChuyenDi();
            addNewTab("Cập nhật chuyển đi", ucupdateCDi);
        }

        private void btnUpdateNK_Click(object sender, EventArgs e)
        {
            UCUpdateNhanKhau ucupdateNK = new UCUpdateNhanKhau();
            addNewTab("Cập nhật nhân khẩu", ucupdateNK);
        }

        private void btnNK15_Click(object sender, EventArgs e)
        {
            frmNK15 nk15 = new frmNK15();
            nk15.Show();
        }
        
        private void btnXoaThuongTru_Click(object sender, EventArgs e)
        {
            UCXoaThuongTru ucxtt = new UCXoaThuongTru();
            addNewTab("Xóa thường trú", ucxtt);
        }

        private void buttonItem14_Click(object sender, EventArgs e)
        {
            //test t = new test();
            //t.Show();
        }

        private void buttonItem15_Click(object sender, EventArgs e)
        {
            //print p = new print();
            //p.Show();
        }

        private void buttonItem16_Click(object sender, EventArgs e)
        {

        }

        // Print 

        [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int size);

        private void buttonItem9_Click(object sender, EventArgs e)
        {
           
        }

        private void btnReport_Click(object sender, EventArgs e)
        {
           frmBaoCaoSHK bcshk = new frmBaoCaoSHK();
            bcshk.Show();
        }

        private void labGioiThieu_Click(object sender, EventArgs e)
        {

        }

        private void btnNVQS_Click(object sender, EventArgs e)
        {
            Report rep = new Report("NVQS",true);
            rep.Savereport("NVQS");
            rep.Print();
        }

        private void btnChiTietSHK_Click(object sender, EventArgs e)
        {

        }

        private void btnBaoCaoTrinhDo_Click(object sender, EventArgs e)
        {
            Report rep = new Report("TrinhDo", true);
            rep.Print();
        }

        private void btnCauHinh_Click(object sender, EventArgs e)
        {

        }

        private void btnChiTietNK15_Click(object sender, EventArgs e)
        {
            frmBaoCaoSHK bcshk = new frmBaoCaoSHK();
            bcshk.Show();
            //frmChiTietNK15 nk15 = new frmChiTietNK15();
            //nk15.ShowDialog();
        }

        
    }
}